﻿#pragma once
#include "SmQuestComponent.h"

#include "SmQuest.h"
#include "Data/SmQuestData.h"

USmQuestComponent::USmQuestComponent(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	
}

void USmQuestComponent::InitializeComponent()
{
	Super::InitializeComponent();

	AActor *Owner = GetOwner();
	InitStepObjectActorInfo(Owner, Owner);	// Default init to our outer owner

	FSmQuestModule& SmQuestModule = FModuleManager::LoadModuleChecked<FSmQuestModule>("SmQuest");
	QuestTable = SmQuestModule.GetSmQuestGlobals()->GetQuestTable();
}

void USmQuestComponent::TickComponent(float DeltaTime, ELevelTick TickType,
	FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// todo Tick里要写重要逻辑，判断Step的条件是否达成
}

void USmQuestComponent::OnRegister()
{
	Super::OnRegister();
}

void USmQuestComponent::OnUnregister()
{
	Super::OnUnregister();
}

void USmQuestComponent::BeginPlay()
{
	Super::BeginPlay();
}

void USmQuestComponent::InitStepObjectActorInfo(AActor* InOwnerActor, AActor* InAvatarActor)
{
	check(StepObjectActorInfo.IsValid());

	StepObjectActorInfo->InitFromActor(InOwnerActor, InAvatarActor, this);
}

void USmQuestComponent::UpdateActorInfoToEquippedSteps(const FSmStepObjectActorInfo* ActorInfo)
{
}

void USmQuestComponent::EquipQuest(FName RowName)
{
	if (IsValid(QuestTable))
	{
		FSmQuestData* SmQuestData = QuestTable->FindRow<FSmQuestData>(RowName, TEXT("USmQuestComponent::EquipQuest"));
	}
}
